package cn.itmantzy.user.controller;

import cn.itmantzy.basic.exception.BusinessException;
import cn.itmantzy.basic.util.AjaxResult;
import cn.itmantzy.user.domain.User;
import cn.itmantzy.user.dto.UserDto;
import cn.itmantzy.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/list")
    public List<User> findAll(){
        return userService.queryAll();
    }


    @PostMapping("/phone/register")
    public AjaxResult phoneRegister(@RequestBody UserDto userDto){
        try {
            userService.phoneRegister(userDto);
            return AjaxResult.getAjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage("程序员正在全力抢修！！！");
        }
    }

}
